﻿var CallLog = {};
//清空搜索条件
$('#btnClear').click(function () {
    $('#hidDepartmentId').val('');
    $('#hidUserId').val('');
    $('#txtEstateNames').val('');
    $('#btnBuilding').val('')
    $('#txtfindTime1').val('');
    $('#txtfindTime2').val('');
});
$(function () {
    EmployeePrompt.getDepartAndEmployeeByInput("txtDepartmentName", "hidDepartmentId", "txtEmployeeName", "hidUserId", false, 'private', 1, '业务员姓名', '请输入部门名称', true, true);
    //初始化CallLog的属性或方法Start  
    CallLog.getEstateUrl = function () {
        var districtKeyIds = '', areaKeyIds = '', estateName = [];
        $('#hidDistrict input[type=checkbox]:checked').each(function () {
            districtKeyIds += $(this).val() + ',';
        });
        $('#hidArea input[type=checkbox]:checked').each(function () {
            areaKeyIds += $(this).val() + ',';
        });
        estateName = $('#txtEstateNames').val().split('+');
        return '/property/estates-for-region-keyids-obtain-ajax?DistrictKeyIds=' + districtKeyIds.substr(0, districtKeyIds.length - 1) + '&AreaKeyIds=' + areaKeyIds.substr(0, areaKeyIds.length - 1) + '&EstateName=' + escape(estateName[estateName.length - 1]);
    };
    //初始化CallLog的属性或方法End


    //初始化build的属性或方法Start  
    CallLog.getbuildUrl = function () {
        return '/property/building-for-estate-obatin-ajax?EstateName=' + escape($("#txtEstateNames").val()) + '&BuildName=' + $("#btnBuilding").val();
    };

    //楼盘自动完成及赋值隐藏域
    $("#txtEstateNames").autocomplete(CallLog.getEstateUrl, {
        width: 260,
        max: 1000,
        Default: 1,
        selectFirst: false,
        cacheLength: 0,
        multiple: true,
        multipleSeparator: '+',
        formatItem: function (row) {
            return row.EstateFullName;
        },
        formatResult: function (row) {
            return row.EstateName;

        }
    }).result(function (a, b) {
        $("#txtEstateNames").attr('isexistbuild', 'true');
        $("#btnBuilding").removeAttr("readonly");
    });

    $('#txtEstateNames').bind('change', function () {
        $('#btnBuilding').val('');
        $("#hidBuildKeyId").val('');
        $('#hidBuilding ul').html('');
        $(this).attr('isexistbuild', 'true');
        if ($(this).val() == "") {
            $("#btnBuilding").attr("readonly", "readonly").val("");
        }

    });

    //栋座自动完成及赋值隐藏域
    $("#btnBuilding").autocomplete(CallLog.getbuildUrl, {
        width: 260,
        max: 1000,
        Default: 1,
        selectFirst: false,
        cacheLength: 0,
        multiple: true,
        clickMode: true,
        minChars: 0,
        formatItem: function (row) {
            return row.BuildingName;
        },
        formatResult: function (row) {

            return row.BuildingName;
        }
    }).result(function (a, b) {
        $("#hidBuildKeyId").val(b.KeyId);
    });
    //是否是点击submit，主要判断是否生成json
    CallLog.isSubmit = function (element) {
        $(element).attr('isSubmitValue', 'true');
    };
});

function setPageStartTime() {
    window.pageStartTime = new Date();
}
function setPageEndTime() {
    $("#timeCount").html("查询耗时" + timehelper.TimeDiffirence(window.pageStartTime, new Date()).msDiff + "毫秒");
}
var loadscript = {};

loadscript.beginSearch = function () {
    //此方法在分页控件中
    if ("undefined" != typeof ajaxpageronbegin) {
        ajaxpageronbegin();
    }
    setPageStartTime();
    other.showLoaderMask();
};
loadscript.pageOnSuccessFun = function () {
    setPageEndTime();
    other.hideLoaderMask();
};